import { Injectable } from '@angular/core';

// 服务
import { HttpService } from '../../../http/http.service';

import { EventList,EventHookResult,EventResult } from './event';

import { LocalStorageService } from '../../../store/index'
@Injectable()
export class EventService {
    constructor(
        private httpService: HttpService,
        private localStorageService:LocalStorageService
    ) { }

    // 查询监听配置
    find(count: number, etype: string, action: string, from: string,page:number): Promise<EventList> {
        var param = new Map();
        if (count < 5) {
            count = 5;
        }
        param.set("count", count);
        if (etype != "") {
            param.set("etype", etype)
        }
        if (action != "") {
            param.set("action", action)
        }
        if (from != "") {
            param.set("from", from)
        }
        if (page>1) {
            param.set("page", page)
        }
        return this.httpService.getJSON<EventList>('/admin/event/analysis', param);
    }

    hookinfo( eid:string): Promise<EventHookResult[]> {

        return this.httpService.getJSON<EventHookResult[]>('/admin/event/analysis/hook/'+eid);
    }
    tmpSave(item :EventResult) :void{
        this.localStorageService.setObject("EventService.tmp",item)
    }
    tmp() :EventResult{
    
       return this.localStorageService.getObject("EventService.tmp")
    }
}